<template>
	<view class="look">
		<!-- 查看记录 -->
		<baseInput @inputChange="inputChange" @clearInput="clearInput"></baseInput>
		
		<scroll-view scroll-y="true" class="scroll-box" @scrolltolower="scrolltolower">
			<view class="content">
				<!-- 自有资产 -->
				<view class="item mt46" @click="toDeviceInfo(item.assetOwnership, item.code)" v-for="item in deviceList" :key="item.id">
					<!-- 自有资产头部 -->
					<view class="nav" v-if=" item.assetOwnership === '自有资产' ">
						<image class="image" src="/subpackage-equipment/static/ziyou.png" mode=""></image>
						<text class="text">自有资产</text>
					</view>
					<!-- 租赁资产头部 -->
					<view class="nav" v-else>
						<image class="image" src="/subpackage-equipment/static/zulin.png" mode=""></image>
						<text class="text color">租赁资产</text>
					</view>
					<view class="info">
						<view class="info-item">
							<view class="name">设备名称：</view>
							<view class="value">{{ item.subDeviceTypeName || "" }}</view>
						</view>
						<!-- <view class="info-item">
							<view class="name">入库数量：</view>
							<view class="value">{{ item.num }}台</view>
						</view> -->
						<view class="info-item">
							<view class="name">提交时间：</view>
							<view class="value">{{ item.time || "" }}</view>
						</view>
						<view class="info-item">
							<view class="name">入库编号：</view>
							<view class="value">{{ item.code || "" }}</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import baseInput from "@/components/baseInput/baseInput.vue"
	import { getEqInWarehouseList } from "@/api/device/deviceEntry.js"
	import mixins from "@/utils/mixins.js"
	export default{
		name: "look",
		mixins:[mixins],
		components: {
			baseInput
		},
		data() {
			return {
				obj: {
					projectOrgId: "",            // 组织id
					deviceTypeIds: [],  // 设备类型id
					code: "",          // 设备入库编号
					subDeviceTypeId: "",
					requestMode: 'app',
				},
				pagination:{
					total: "",
					pageSize: 10,
					currentPage: 1
				},
				deviceList: [],     // 设备列表
				bool: false,
			}
		},
		mounted() {
			this.getList()
		},
		methods: {
			// 设备列表数据
			async getList(){
				// 在发送请求就不在发送请求
				if(this.bool){
					return
				}
				if(this.pagination.total !== "" &&  this.deviceList.length !==0  && this.deviceList.length >= this.pagination.total ){
					uni.showToast({
						icon: "none",
						title: "到底了"
					})
					return
				}
				let _data={
					currPage: this.pagination.currentPage,
					pageSize: this.pagination.pageSize,
					params: this.obj
				}
				this.bool = true
				let res = await getEqInWarehouseList(_data)
				console.log(res.result.list,'res')
				let list  = res.result.list.map(item=>({ ...item, time: this.getDate2(item.recordCreateDate)}))
				this.deviceList = [...this.deviceList, ...list]
				this.pagination.total = res.result.total
				this.bool = false
			},
			
			inputChange(value){
				console.log(value,'value')
				if(value){
				this.obj.code=value
				}else {
					this.obj.code=""
				}
				// clearTimeout(this.time)
				// this.time = setTimeout(()=>{
					this.pagination.currentPage = 1
					this.deviceList = []
					this.obj.code = value
					this.getList()
				// },500)
			},
			
			clearInput(){
				this.pagination.currentPage = 1
				this.deviceList = []
				this.obj.code = ""
				this.getList()
			},
			
			scrolltolower(){
				this.pagination.currentPage ++
				this.getList()
				// console.log("待敌了")
			},
			
			toDeviceInfo(type, code){
				console.log(type)
				uni.navigateTo({
					url: `/subpackage-equipment/pages/device/deviceEntry/components/entryInfo?type=${type}&code=${code}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.look{
		padding-top: 30rpx;
		.scroll-box{
			height: calc(100vh - 460rpx);
			padding-top: 10rpx;
			
		}
		.content{
			// margin-top: 40rpx;
			padding-bottom: 40rpx;
			.item{
				width: 100%;
				height: 315rpx;
				background: linear-gradient(180deg, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%);
				box-shadow: 0rpx 0rpx 34rpx 2rpx rgba(47, 128, 237, 0.1);
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				border: 2rpx solid #EBF1FE;
				padding: 0rpx 22rpx;
				box-sizing: border-box;
				
				.nav{
					line-height: 80rpx;
					height: 80rpx;
					border-bottom: 2rpx dashed #E1E1E1;
					padding-bottom: 10rpx;
					
					.image{
						width: 70rpx;
						height: 70rpx;
						vertical-align: middle;
						margin-right: 30rpx;
					}
					.text{
						font-size: 30rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #F99C34;
					}
					.color{
						color: #5EAAFF;
					}
				}
				.info{
					padding-left: 15rpx;
					.info-item{
						display: flex;
						font-size: 28rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #445469;
						margin-top: 22rpx;
					}
				}
			}
			.mt46{
				margin-top: 35rpx;
			}
		}
	}
</style>
